<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>猜数字</title>
</head>
<body>
    <!-- <h1>猜数字游戏</h1>
    <div>请输入要猜的数字</div>
    <input id="input_Num" type="text">
    <button onclick="queren()">提交</button>
    <div id="result"></div>

    <script>
        queren =function(){
            var gus=parseInt(Math.random()*100)+1;
            console.log(gus);
        var num=document.getElementById("input_Num").vaule;
        var msg;
        if(num==gus)
        {
            msg="<h4> 恭喜你，猜对了！！！</h4>";
        }
        else
        {
            msg="<h4> 猜错了，答案是"+gus+"</h4>";
        }

        document.getElementById('result').innerHTML=msg;

        }
        
    </script> -->



    <h1>猜数字游戏</h1>
    <div>请输入要猜的数字</div>
    <input  type="text">
    <button >提交</button>
    <div class="result"></div>

     <script>
        let toGuess=parseInt(100*Math.random())+1;
        console.log(toGuess);
        let input=document.querySelector('input');
        let button=document.querySelector('button');
        let resultDiv=document.querySelector('.result');
        button.onclick=function(){
            if(input.value=='')
            {
                return;
            }
            let inputNum=parseInt(input.value);
            if(toGuess>inputNum)
            {
                resultDiv.innerHTML='小了';
            }
            else if(toGuess<inputNum)
            {
                resultDiv.innerHTML='大了';
            }
            else
            {
                resultDiv.innerHTML='猜对了';
            }
        }
    </script> 


</body>
</html>